﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_BOM_ITEM_MATERIAL
// * CreateDate    : 2013-11-25 16:35:38
// * Creater       : CodeSmith
// * LastChangeDate: 2013-11-25 16:35:38
// * LastChanger   : 2013-11-25 16:35:38
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Bpt
{
    /// <summary>
    /// BomItemMaterial
    /// </summary>
    public partial class BomTechnicItemMtrlBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objBomTechnicItemMtrlEntity">Entity</param>
        /// <returns>Entity</returns>
        public static BomTechnicItemMtrlEntity GetBomTechnicItem(BomTechnicItemMtrlEntity objBomTechnicItemMtrlEntity)
        {
            return DataAccess.SelectSingle<BomTechnicItemMtrlEntity>(objBomTechnicItemMtrlEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objBomTechnicItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertBomTechnicItem(BomTechnicItemMtrlEntity objBomTechnicItemMtrlEntity)
        {
            return DataAccess.Insert(objBomTechnicItemMtrlEntity);
        }

        public static bool InsertBomTechnicItem(List<BomTechnicItemMtrlEntity> objBomTechnicItemMtrlEntityList)
        {
            return DataAccess.Insert(objBomTechnicItemMtrlEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objBomTechnicItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateBomTechnicItem(BomTechnicItemMtrlEntity objBomTechnicItemMtrlEntity)
        {
            return DataAccess.Update(objBomTechnicItemMtrlEntity);
        }

        public static bool UpdateBomTechnicItem(List<BomTechnicItemMtrlEntity> objBomTechnicItemMtrlEntityList)
        {
            return DataAccess.Update<BomTechnicItemMtrlEntity>(objBomTechnicItemMtrlEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objBomTechnicItemMtrlEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteBomTechnicItem(BomTechnicItemMtrlEntity objBomTechnicItemMtrlEntity)
        {
            return DataAccess.Delete(objBomTechnicItemMtrlEntity);
        }

        public static bool DeleteBomTechnicItem(List<BomTechnicItemMtrlEntity> objBomTechnicItemMtrlEntityList)
        {
            return DataAccess.Delete<BomTechnicItemMtrlEntity>(objBomTechnicItemMtrlEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetBomTechnicItemAll()
        {
            return DataAccess.SelectAllDataSet<BomTechnicItemMtrlEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<BomTechnicItemMtrlEntity> GetBomTechnicItemAllList()
        {
            return DataAccess.SelectAll<BomTechnicItemMtrlEntity>();
        }
        #endregion



        public static List<BomTechnicItemMtrlEntity> GetBomTechnicItemMtrlByTechnicId(string techId)
        {
            if (string.IsNullOrEmpty(techId))
                return null;
            return DataAccess.Select<BomTechnicItemMtrlEntity>(new BomTechnicItemMtrlEntity { BomTechnicId = techId });
        }

        public static List<BomTechnicItemMtrlEntity> GetBomTechnicItemMtrlByTechnicItemId(string technicItemId)
        {
            if (string.IsNullOrEmpty(technicItemId))
                return null;
            return DataAccess.Select<BomTechnicItemMtrlEntity>(new BomTechnicItemMtrlEntity { BomTechnicItemId = technicItemId });
        }


        public static bool Save(List<BomTechnicItemMtrlEntity> news, List<BomTechnicItemMtrlEntity> updates, List<BomTechnicItemMtrlEntity> dels)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Delete(dels, broker);
                    DataAccess.Update(updates, broker);
                    DataAccess.Insert(news, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }

        }

    }


}

